package test_junit_merchant.ManageMerchant;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.util.Random;

/**
 * Created by ZH on 2018/2/2.
 * 商户-工区工位新增
 */
public class WorkArea {
    private WebDriver driver;
    private static WorkArea wa = new WorkArea();
    public static WorkArea getInstance(){
        return wa;
    }

    public WebDriver getwDriver(){
        return driver;
    }
    public void setwDriver(WebDriver w){
        driver = w;
    }

    public void cloudAdd() throws InterruptedException {
        Thread.sleep(2000);
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/iframe")));
        driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div/div[1]/button[1]")).click();
        Thread.sleep(2000);
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/iframe")));
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"layui-layer-iframe1\"]")));
        driver.findElement(By.id("1_anchor")).click();
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/iframe")));
        driver.findElement(By.xpath("/html/body/div[4]/div[3]/a[1]")).click();
        Thread.sleep(2000);
    }

    public void addWorkArea() throws InterruptedException {
        int i = 3;
        Random r = new Random();
        String flag = "0";
        while(i-- > 0){
            flag += r.nextInt(10);
        }

        Thread.sleep(2000);
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/iframe")));
        Thread.sleep(1000);
        driver.findElement(By.id("172_anchor")).click();
        Thread.sleep(2000);
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/iframe")));
        driver.findElement(By.id("add_btn")).click();
        driver.findElement(By.xpath("//*[@id=\"list\"]/li[1]/input")).sendKeys("测试工位"+flag);
        driver.findElement(By.xpath("//*[@id=\"list\"]/li[1]/div/button[1]")).click();
        Thread.sleep(2000);
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.findElement(By.xpath("/html/body/div[4]/div[3]/a")).click();
    }

}
